<template>
  <div class='screen-list-container'>
    <h2 class="title">智慧工地大屏</h2>
    <div class="screen-list">
      <div v-for="item in screenList.list"
           @click="toPreview(item)"
           :key="item.categ_id"
           class="screen-list-item">
        <img src="@/assets/screen-default.png"
             v-if="!item.logo"
             alt="">
        <img :src="item.logo"
             v-if="item.logo"
             alt="">
        <div class="screen-info">
          <p>{{item.categ_name}}</p>
          <!-- <span>{{item.update_user_name}}</span> -->
        </div>
      </div>
      <div v-for="(item,index) in placeholderList"
           :key="index"
           class="screen-list-item placeholder">
      </div>
    </div>
  </div>
</template>
<script>
import { standardCodeApi } from '@/services/StandardCode'
export default {
  data () {
    return {
      screenList: {
        list: [

        ]
      },
      requestParams: {
        system_no: this.$route.query.system_no || 'intecons',
        categ_no: this.$route.query.categ_no || '',
        is_page: 0,
        page: 1,
        page_size: 30
      },
      placeholderList: []
    }
  },
  methods: {
    getScreenList () {
      standardCodeApi.getInstanceAllList({//所有的实例模板
        params: this.requestParams
      }).then(res => {
        if (res.code === 0) {
          this.screenList = res.data
          let length = res.data.list.length
          this.placeholderList = new Array(4 - length % 4).fill({})
        }
      })
    },
    // 跳转到大屏预览页
    toPreview (item) {
      // let prefix = 'http://dev_console.ihibuilding.cn/pagePreview'

      let prefix = process.env.screenUrl
      let companyId = window.localStorage.getItem('comp_id') || ''
      let choosedProject = this.$store.state.choosedProject || {}
      let projectId = choosedProject.project_id
      let projectName = choosedProject.nick_name
      let isMock = this.$route.query.is_mock || '0'
      let url =
        `${prefix}?from=pageInstance&categ_no=${item.categ_no}&useage=${item.useage}&project_id=${projectId}&is_mock=${isMock}&projectName=${projectName}`
      window.open(url)
    }
  },
  created () {
    this.getScreenList()
  },
  mounted () {
  }
}
</script>
<style scoped lang='scss'>
.screen-list-container {
  .title {
    font-size: 16px;
    font-weight: bold;
    color: rgba($color: #000000, $alpha: 0.85);
    line-height: 54px;
    padding-left: 20px;
    border-bottom: 1px solid #e6e6e6;
  }
  .screen-list {
    width: 100%;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;

    .screen-list-item {
      // width: 256px;
      width: 22%;
      height: 240px;
      display: flex;
      flex-direction: column;
      background: #ffffff;
      border-radius: 4px;
      box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.12);
      margin-bottom: 20px;
      cursor: pointer;
      &.placeholder {
        visibility: hidden;
      }
      img {
        width: 100%;
        height: 144px;
      }
      .screen-info {
        width: 100%;
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 20px;

        p {
          font-size: 16px;
          font-weight: bold;
          color: rgba($color: #000000, $alpha: 0.85);
        }
        span {
          font-size: 12px;
          color: rgba($color: #000000, $alpha: 0.45);
        }
      }
    }
  }
}
</style>